#include<bits/stdc++.h>
using namespace std;
int n, m, w[10005] = {0}, slt[105] = {0}, k = 1, cnt = 0;
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> w[i];
	}
	for (int i = 1; i <= m; i++)
	{
		slt[i] = w[k++];
	}
	while (k <= n)
	{
		int minn1 = 9999999;
		for (int i = 1; i <= m; i++)
		{
			if (slt[i] <= minn1)
			{
				minn1 = slt[i];
			}
		}
		cnt += minn1;
		for (int i = 1; i <= m; i++)
		{
			slt[i] -= minn1;
		}
		for (int i = 1; i <= m; i++)
		{
			if (slt[i] == 0)
			{
				slt[i] = w[k++];
			}
		}
	}
	int maxx = -1;
	for (int i = 1; i <= m; i++)
	{
		if (slt[i] > maxx)
		{
			maxx = slt[i];
		}
	}
	cnt += maxx;
	cout << cnt;
	return 0;
}

